package com.woniu.zsd.merchant.controller;


import com.woniu.dto.QueryToInfoDto;
import com.woniu.form.ChatMessage;
import com.woniu.form.QueryChatHistoryForm;
import com.woniu.zsd.commons.core.model.Result;
import com.woniu.zsd.merchant.service.IChatHistoryService;
import com.woniu.zsd.permission.Permission.Permission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2025-03-27
 */
@RestController
@RequestMapping("/chat-history")
@Api(tags = "聊天记录管理")
public class ChatHistoryController {
    @Autowired
    private IChatHistoryService chatHistoryService;

    @ApiOperation("用户查询聊天记录")
    @GetMapping("/query")
    public Result<List<ChatMessage>> queryChatHistory(
            @ApiParam(value = "发送用户id") @RequestHeader String token,
            @ApiParam(value = "接收用户id") String toId
    ) {
        return new Result<List<ChatMessage>>().setCode(200).setMsg("查询聊天记录成功").setData(chatHistoryService.getChatHistory(token, toId));
    }

    @ApiOperation("用户查询聊天对象信息")
    @GetMapping("/query/toInfo")
    public Result<List<QueryToInfoDto>> queryToInfo(
            @ApiParam(value = "发送用户id") @RequestHeader String token
    ) {
        return new Result<List<QueryToInfoDto>>().setCode(200).setMsg("查询聊天对象信息成功").setData(chatHistoryService.queryToInfo(token));
    }
}
